﻿Ext.define('app.system.area.Edit',
{
    extend: 'Ext.window.Window',
    autoScroll: true,
    title: '新增区域',
    modal: true,
    width: 300,
    height: 120,
    layout: 'fit',
    parentNodeId: 0,
    nodeId: 0,
    nodeText: '',
    bodyStyle: 'padding:10px 10px 0 0',
    initComponent: function () {
        var me = this;
        if (me.nodeId > 0)
        {
            me.title = "编辑区域";
        }
        me.items = [me.getAreaForm()];
        me.buttons = [
            {
                text: '保存', scope: this, handler: function () {
                    var form = me.getAreaForm().getForm();
                    if (!form.isValid()) {
                        return false;
                    }
                    var values = me.getAreaForm().getValues();
                    App.AjaxPost('/api/services/app/quan/CreateQuan', values, function (data) {
                        me.fireEvent("savesuccess");
                    });
                }
            },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getAreaForm: function () {
        var me = this;
        if (!this.areaForm) {
            this.areaForm = new Ext.form.Panel({
                border: false,
                defaults: {
                    anchor: '100%',
                    labelWidth:40,
                    xtype: 'textfield',
                    labelAlign: "right"
                },
                items: [
                    {
                        fieldLabel: '名称',
                        allowBlank: false,
                        name: 'name',
                        value: me.nodeText
                    },
                    {
                        xtype: 'hidden',
                        name: 'parentId',
                        value: me.parentNodeId
                    },
                    {
                        xtype: 'hidden',
                        name: 'curId',
                        value: me.nodeId
                    }
                ]
            });
        }
        return this.areaForm;
    }
});